public class SearchMatrix {
    public static void main(String[] args) {
        int[][] test= {{1,3,5,7},{10,11,16,20},{23,30,34,60}};
        int[][] test2= {{1},{3}};
        System.out.println(search(test2, 13));
    }

    public static boolean search(int[][] matrix,int target){
        int row = matrix.length;

        int col = matrix[0].length;

        int end = row * col -1;
        int start = 0;
        while(start <= end){
            int mid = (start + end)/2;
            int mid1 = mid / col;
            int mid2 = mid % col;
            if(matrix[mid1][mid2] > target){
                end = mid - 1;
            }else if(matrix[mid1][mid2] < target){
                start = mid + 1;
            }else {
                return true;
            }
        }
        return false;
    }
}
